import { constantRoutes, asyncRouter } from '@/router/index.js'
export default {
  namespaced: true,
  state() {
    return {
      routes: [...constantRoutes]// 静态路由和用户的动态路由
    }
  },
  mutations: {
    // 设置菜单
    setRoutes(state, data) {
      state.routes = [...constantRoutes, ...data]
      console.log(state.routes, '8888888')
    }
  },
  actions: {
    filterRoutes(ctx, menuList) {
      console.log(menuList, '这是仓库存储的权限')
      const userAsyncRoutes = []
      asyncRouter.forEach(item => {
        if (menuList.find(obj => obj.route === item.path)) {
          if (item.children && item.children.length) {
            const temp = item.children.filter(val => {
              return menuList.find(o => o.route === val.path)
            })
            item.children = temp
          }
          userAsyncRoutes.push(item)
        }
      })

      // 追加404页面
      userAsyncRoutes.push({ path: '*', redirect: '/404', hidden: true })
      ctx.commit('setRoutes', userAsyncRoutes)
      return userAsyncRoutes
    }

  },
  getters: {}
}
